<template>
    <div class="f-menu" :style="{ width: $store.state.asideWidth }">
        <el-menu
            :default-active="$route.path"
            :collapse-transition="false"
            unique-opened
            :collapse="isCollapse"
            @select="handleSelect"
        >
            <template v-for="(item, index) in asideMenus" :key="index">
                <el-sub-menu v-if="item.child && item.child.length" :index="item.name">
                    <template #title>
                        <el-icon v-if="item.icon">
                            <component :is="item.icon" class="icon"></component>
                        </el-icon>
                        <span>{{ item.name }}</span>
                    </template>
                    <el-menu-item :index="item2.frontpath" v-for="(item2, index2) in item.child" :key="index2">
                        <el-icon v-if="item2.icon">
                            <component :is="item2.icon" class="icon"></component>
                        </el-icon>
                        <template #title>{{ item2.name }}</template>
                    </el-menu-item>
                </el-sub-menu>
                <el-menu-item :index="item.frontpath" v-else>
                    <el-icon v-if="item.icon">
                        <component :is="item.icon" class="icon"></component>
                    </el-icon>
                    <template #title>{{ item.name }}</template>
                </el-menu-item>
            </template>
      </el-menu>
    </div>
</template>
<script setup>
import { computed, ref } from 'vue'
import { useStore } from 'vuex'
import { useRouter } from 'vue-router'

const store = useStore()
const router = useRouter()

// 是否展开菜单
const isCollapse = computed(() => !(store.state.asideWidth == "250px"))

// 菜单选中事件
const handleSelect = (path) => {
    router.push({ path })
}

// 菜单列表
const asideMenus = computed(() => store.state.menus)
</script>
<style lang="scss" scoped>
.f-menu {
    position: fixed;
    background: #fdfdfd;
    z-index: 60;
    overflow: auto;
    box-shadow: 2px 0 8px rgb(29 35 41 / 5%);
    top: 64px;
    left: 0;
    bottom: 0;
}
.f-menu::-webkit-scrollbar {
    width: 0px;
}
.icon {
    font-size: 1.2em;
}
</style>